<?php
namespace app\admin\validate;

use \think\Validate;
use \think\Db;

class Article extends Validate
{
    use \app\common\validate\Validate;

    protected $rule = [
        'title'             => ['require', 'max:255'],
        'keyword'           => ['max:100'],
        'status'            => ['in:0,1'],
        'thumbnail'         => ['max:255'],
        'description'       => ['max:255'],
        'category_id'       => ['require', 'exist:category'],//这里可以权限判断
        'content'           => ['requireIf:is_link,0'],
    ];

    protected $message = [
        'category_id.require'  => '分类必须填写',
        'category_id.existPid' => '分类不存在或者不能等于本身',
        'title.require'        => '标题必须填写',
        'title.max'            => '标题长度不能超来100个字符',
        'title.unique'         => '标题已存在',
        'keyword.max'          => '关键词长度不能超来100个字符',
        'description.max'      => '简介长度不能超来100个字符',
        'status.in'            => '状态值不可用',
        'content.requireIf'    => '内容必须填写',

    ];

    protected $scene = [
        //'add'  => ['category_id', 'title', 'keyword', 'status', 'sort'],
        //'edit' => ['category_id', 'title', 'keyword', 'status', 'sort'],
    ];

    public function __construct()
    {
        parent::__construct();

/*        parent::__construct(
            [//rule
                'title' => ['require', 'max:255','unique:archive,title'],
            ],
            [//msg
                'title.require'
            ]
        );*/


    }
}
